package com.ellricky.tv.ui

import android.content.Intent
import android.content.pm.ActivityInfo
import android.os.Bundle
import com.andr.common.ui.activity.BaseActivity
import com.andr.common.ui.mvp.BasePresenter
import com.andr.common.util.ActivityUtil

abstract class BaseTvActivity<V, T : BasePresenter<V>> : BaseActivity<V, T>() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        try {
            parseParams()

            initOnclick()

            fetchData()
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    abstract fun fetchData()

    open fun parseParams() {

    }

    open fun initOnclick() {

    }

    fun logout() {
        val intent = Intent(this, TvLoginActivity::class.java)
                .apply {
                    putExtra("fromMain", true)
                }
        startActivity(intent)
        ActivityUtil.finishAll()
    }

    override fun setOrientation() {
        this.requestedOrientation =
                ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
    }
}